<html>
<head>
<title>.::แสดงรายงาน::.</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="Content-Type" content="application/force-download">
<meta http-equiv="Content-Type" content="application/octet-stream">
<meta http-equiv="Content-Type" content="aplication/download"> 
<script type="text/javascript">
    loadPageFull(0, 0, 0, 0);
</script>
<style type="text/css" media="print">
 
	input{
 
	display:none;
 
	}
 
	</style>
</head>
<body bgcolor="#F5F5DC">
    <div align="left"><input type="button" name="btPrint" value=" PrintPage " onClick="javascript:window.print();"/>
    <input type="button" name="btClose" value="ClosePage" onClick="javascript:window.close();"/>
    </div>
<?
    $reportType = $_GET['reportType'];
//    echo $reportType;
    if($reportType==1){
?>
    <table width="100%" border="1" align="center" cellpadding="0" cellspacing="0" bordercolor="#000000" bgcolor="#FFFFFF">
  <tr>
    <td colspan="6"><div align="center" class="style16bold">รายงานแสดงข้อมูลผู้สมัครทั้งหมด</div></td>
  </tr>
  <tr>
    <td><div align="center" class="style16bold">ลำดับ</div></td>
    <td><div align="center" class="style16bold">เลขที่สมัคร</div></td>
    <td><div align="center" class="style16bold">ชื่อ - สกุล </div></td>
    <td><div align="center" class="style16bold">วันที่สมัคร</div></td>
    <td><div align="center" class="style16bold">ระดับชั้นที่สมัคร</div></td>
    <td><div align="center" class="style16bold">ที่อยู่ตามทะเบียนบ้าน</div></td>
  </tr>
  <?
  $count = 0;
  $dateYear = date(Y)+543;
  $report = new MySQL(_MySQL);
  $sql = "SELECT r.regisid ,stu.title ,stu.firstname ,stu.lastname ,r.regisdate ,rt.name ,rp.plan ";
  $sql = $sql." ,ad.address ,ad.moo ,ad.village ,ad.subdistrict ,ad.district ,ad.province ";
  $sql = $sql." FROM regis r ,study stu ,registype rt ,regisplan rp ,address ad ";
  $sql = $sql." WHERE r.studyid = stu.studyid AND r.registypeid = rt.registypeid AND r.regisplanid = rp.regisplanid ";
  $sql = $sql." AND r.censusaddressid = ad.addressid AND r.eduyear = '$dateYear'";

    $rest = mysql_query($sql);
    while($row = mysql_fetch_array($rest))
    {
        $regisid = $row[0];
        $nameRegis = $row[1].$row[2]." ".$row[3];
        $regisDate = $row[4];
        $regisTypeName = $row[5]." ".$row[6];
        $address = $row[7]." หมู่".$row[8]." ต.".$row[10]." อ.".$row[11]." จ.".$row[12];
    echo "<tr>";
    echo "<td align='center'>".++$count."</td>";
    echo "<td align='center'>".$regisid."</td>";
    echo "<td align='center'>".$nameRegis."</td>";
    echo "<td align='center'>".$regisDate."</td>";
    echo "<td align='center'>".$regisTypeName."</td>";
    echo "<td align='center'>".$address."</td>";
    echo "</tr>";
  }  
  
    mysql_query("SET character_set_results=tis620");  
    $result = mysql_query($sql);
if($result){ 
//////////////////////////////////////////////////////////
//*** Get Document Path ***//
$strPath = realpath(basename(getenv($_SERVER["SCRIPT_NAME"]))); // C:/AppServ/www/myphp
 
//*** Excel Document Root ***//
$strFileName = "MyXls/MyExcel_Type1.xls";
 
//*** Connect to Excel.Application ***//
$xlApp = new COM("Excel.Application");
$xlBook = $xlApp->Workbooks->Add();
 
 
//*** Create Sheet 1 ***//
$xlBook->Worksheets(1)->Name = "RegisOnline";                        
$xlBook->Worksheets(1)->Select;
 
//*** Width & Height (A1:A1) ***//
$xlApp->ActiveSheet->Range("A1:A1")->ColumnWidth = 10.0;
$xlApp->ActiveSheet->Range("B1:B1")->ColumnWidth = 13.0;
$xlApp->ActiveSheet->Range("C1:C1")->ColumnWidth = 40.0;
$xlApp->ActiveSheet->Range("D1:D1")->ColumnWidth = 40.0;
$xlApp->ActiveSheet->Range("E1:E1")->ColumnWidth = 40.0;
$xlApp->ActiveSheet->Range("F1:F1")->ColumnWidth = 40.0;
 
//*** Report Title ***//
$xlApp->ActiveSheet->Range("A1:F1")->BORDERS->Weight = 1;
$xlApp->ActiveSheet->Range("A1:F1")->MergeCells = True;
$xlApp->ActiveSheet->Range("A1:F1")->Font->Bold = True;
$xlApp->ActiveSheet->Range("A1:F1")->Font->Size = 20;
$xlApp->ActiveSheet->Range("A1:F1")->HorizontalAlignment = -4108;             
$xlApp->ActiveSheet->Cells(1,1)->Value = "RegisOnline Report";
 
//*** Header ***//             
$xlApp->ActiveSheet->Cells(3,1)->Value = "NO.";
$xlApp->ActiveSheet->Cells(3,1)->Font->Bold = True;
$xlApp->ActiveSheet->Cells(3,1)->VerticalAlignment = -4108;
$xlApp->ActiveSheet->Cells(3,1)->HorizontalAlignment = -4108;
$xlApp->ActiveSheet->Cells(3,1)->BORDERS->Weight = 1;
 
$xlApp->ActiveSheet->Cells(3,2)->Value = "REGISID";
$xlApp->ActiveSheet->Cells(3,2)->Font->Bold = True;
$xlApp->ActiveSheet->Cells(3,2)->VerticalAlignment = -4108;
$xlApp->ActiveSheet->Cells(3,2)->HorizontalAlignment = -4108;
$xlApp->ActiveSheet->Cells(3,2)->BORDERS->Weight = 1;
 
$xlApp->ActiveSheet->Cells(3,3)->Value = "NAME";
$xlApp->ActiveSheet->Cells(3,3)->Font->Bold = True;
$xlApp->ActiveSheet->Cells(3,3)->VerticalAlignment = -4108;
$xlApp->ActiveSheet->Cells(3,3)->HorizontalAlignment = -4108;
$xlApp->ActiveSheet->Cells(3,3)->BORDERS->Weight = 1;
 
$xlApp->ActiveSheet->Cells(3,4)->Value = "DATEREGIS";
$xlApp->ActiveSheet->Cells(3,4)->Font->Bold = True;
$xlApp->ActiveSheet->Cells(3,4)->VerticalAlignment = -4108;
$xlApp->ActiveSheet->Cells(3,4)->HorizontalAlignment = -4108;
$xlApp->ActiveSheet->Cells(3,4)->BORDERS->Weight = 1;
 
$xlApp->ActiveSheet->Cells(3,5)->Value = "LEVELREGIS";
$xlApp->ActiveSheet->Cells(3,5)->Font->Bold = True;
$xlApp->ActiveSheet->Cells(3,5)->VerticalAlignment = -4108;
$xlApp->ActiveSheet->Cells(3,5)->HorizontalAlignment = -4108;
$xlApp->ActiveSheet->Cells(3,5)->BORDERS->Weight = 1;
 
$xlApp->ActiveSheet->Cells(3,6)->Value = "ADDRESS";
$xlApp->ActiveSheet->Cells(3,6)->Font->Bold = True;
$xlApp->ActiveSheet->Cells(3,6)->VerticalAlignment = -4108;
$xlApp->ActiveSheet->Cells(3,6)->HorizontalAlignment = -4108;
$xlApp->ActiveSheet->Cells(3,6)->BORDERS->Weight = 1;
 
//***********//
 $count = 0;
$intRows = 4;
$num_row = mysql_num_rows($result);
while($objResult = mysql_fetch_array($result))
{
 
//*** Detail ***//
$xlApp->ActiveSheet->Cells($intRows,1)->Value = ++$count;
$xlApp->ActiveSheet->Cells($intRows,1)->BORDERS->Weight = 1;
$xlApp->ActiveSheet->Cells($intRows,1)->HorizontalAlignment = -4108;
 
$xlApp->ActiveSheet->Cells($intRows,2)->Value = $objResult[0];
$xlApp->ActiveSheet->Cells($intRows,2)->BORDERS->Weight = 1;
 
$xlApp->ActiveSheet->Cells($intRows,3)->Value = $objResult[1].$objResult[2]." ".$objResult[3];
$xlApp->ActiveSheet->Cells($intRows,3)->BORDERS->Weight = 1;
 
$xlApp->ActiveSheet->Cells($intRows,4)->Value = $objResult[4];
$xlApp->ActiveSheet->Cells($intRows,4)->HorizontalAlignment = -4108;
$xlApp->ActiveSheet->Cells($intRows,4)->BORDERS->Weight = 1;
 
$xlApp->ActiveSheet->Cells($intRows,5)->Value = $objResult[5]." ".$objResult[6];
$xlApp->ActiveSheet->Cells($intRows,5)->BORDERS->Weight = 1;
//$xlApp->ActiveSheet->Cells($intRows,5)->NumberFormat = "$#,##0.00";
 
$xlApp->ActiveSheet->Cells($intRows,6)->Value = $objResult[7]." m.".$objResult[8]." sd.".$objResult[10]." d.".$objResult[11]." p.".$objResult[12];
$xlApp->ActiveSheet->Cells($intRows,6)->BORDERS->Weight = 1;

 
$intRows++;
}              
 
@unlink($strFileName); //*** Delete old files ***//
 
$xlBook->SaveAs($strPath."/".$strFileName); //*** Save to Path ***//
//$xlBook->SaveAs(realpath($strFileName)); //*** Save to Path ***//
 
//*** Close & Quit ***//
$xlApp->Application->Quit();
$xlApp = null;
$xlBook = null;
$xlSheet1 = null;

//////////////////////////////////////////////////////////    
}  
//  echo "count: ".$count;
  ?>
<!--  <font color="red">Excel Created <a href="<?=$strFileName?>">Click here</a> to Download.</font> -->
  <button name="btExcell" onclick="javascript:window.open('/regisonline/<?=$strFileName?>');">Create File Excel.</button>
    <tr>
        <td colspan="6" align="right" class="style16bold">จำนวนรวม <?=$count?> ราย</td>
    </tr>
</table>  
    <?
    }else if($reportType==2){
?>
    <table width="100%" border="1" align="center" cellpadding="0" cellspacing="0" bordercolor="#000000" bgcolor="#FFFFFF">
  <tr>
    <td colspan="8"><div align="center" class="style16bold">รายงานแสดงผู้สมัครตามที่อยู่ โรงเรียนเดิม และจังหวัด</div></td>
  </tr>
  <tr>
    <td><div align="center" class="style16bold">ลำดับ</div></td>
    <td><div align="center" class="style16bold">เลขที่สมัคร</div></td>
    <td><div align="center" class="style16bold">ชื่อ - สกุล </div></td>
    <td><div align="center" class="style16bold">วันที่สมัคร</div></td>
    <td><div align="center" class="style16bold">ระดับชั้นที่สมัคร</div></td>
    <td><div align="center" class="style16bold">ที่อยู่ตามทะเบียนบ้าน</div></td>
    <td><div align="center" class="style16bold">โรงเรียนเดิม</div></td>
    <td><div align="center" class="style16bold">จังหวัด</div></td>
  </tr>
  <?
  $count = 0;
  $dateYear = date(Y)+543;
  $report = new MySQL(_MySQL);
  $sql = "SELECT r.regisid ,stu.title ,stu.firstname ,stu.lastname ,r.regisdate ,rt.name ,rp.plan ";
  $sql = $sql." ,ad.address ,ad.moo ,ad.village ,ad.subdistrict ,ad.district ,ad.province ,edu.fromschool "; 
  $sql = $sql." FROM regis r ,study stu ,registype rt ,regisplan rp ,address ad ,education edu ";
  $sql = $sql." WHERE r.studyid = stu.studyid AND r.registypeid = rt. registypeid AND r.regisplanid = rp.regisplanid ";
  $sql = $sql." AND r.censusaddressid = ad.addressid AND r.eduid = edu.eduid AND r.eduyear = '$dateYear' order by edu.fromschool";
    $result = mysql_query($sql);
    while($row = mysql_fetch_array($result))
    {
        $regisid = $row[0];
        $nameRegis = $row[1].$row[2]." ".$row[3];
        $regisDate = $row[4];
        $regisTypeName = $row[5]." ".$row[6];
        $address = $row[7]." หมู่".$row[8]." ต.".$row[10]." อ.".$row[11]." จ.".$row[12];
        $fromSchool = $row[13];
        $province = $row[12];
        ++$count;
    echo "<tr>";
    echo "<td align='center'>".$count."</td>";
    echo "<td align='center'>".$regisid."</td>";
    echo "<td align='center'>".$nameRegis."</td>";
    echo "<td align='center'>".$regisDate."</td>";
    echo "<td align='center'>".$regisTypeName."</td>";
    echo "<td align='center'>".$address."</td>";
    echo "<td align='center'>".$fromSchool."</td>";
    echo "<td align='center'>".$province."</td>";    
    echo "</tr>";
  }
    $count = 0;
  
    mysql_query("SET character_set_results=tis620");  
    $result = mysql_query($sql);
if($result){ 
//////////////////////////////////////////////////////////
//*** Get Document Path ***//
$strPath = realpath(basename(getenv($_SERVER["SCRIPT_NAME"]))); // C:/AppServ/www/myphp
 
//*** Excel Document Root ***//
$strFileName = "MyXls/MyExcel_Type2.xls";
 
//*** Connect to Excel.Application ***//
$xlApp = new COM("Excel.Application");
$xlBook = $xlApp->Workbooks->Add();
 
 
//*** Create Sheet 1 ***//
$xlBook->Worksheets(1)->Name = "RegisOnline";                        
$xlBook->Worksheets(1)->Select;
 
//*** Width & Height (A1:A1) ***//
$xlApp->ActiveSheet->Range("A1:A1")->ColumnWidth = 10.0;
$xlApp->ActiveSheet->Range("B1:B1")->ColumnWidth = 13.0;
$xlApp->ActiveSheet->Range("C1:C1")->ColumnWidth = 23.0;
$xlApp->ActiveSheet->Range("D1:D1")->ColumnWidth = 23.0;
$xlApp->ActiveSheet->Range("E1:E1")->ColumnWidth = 40.0;
$xlApp->ActiveSheet->Range("F1:F1")->ColumnWidth = 40.0;
$xlApp->ActiveSheet->Range("G1:G1")->ColumnWidth = 40.0;
$xlApp->ActiveSheet->Range("H1:H1")->ColumnWidth = 12.0;
 
//*** Report Title ***//
$xlApp->ActiveSheet->Range("A1:F1")->BORDERS->Weight = 1;
$xlApp->ActiveSheet->Range("A1:F1")->MergeCells = True;
$xlApp->ActiveSheet->Range("A1:F1")->Font->Bold = True;
$xlApp->ActiveSheet->Range("A1:F1")->Font->Size = 20;
$xlApp->ActiveSheet->Range("A1:F1")->HorizontalAlignment = -4108;             
$xlApp->ActiveSheet->Cells(1,1)->Value = "RegisOnline Report";
 
//*** Header ***//             
$xlApp->ActiveSheet->Cells(3,1)->Value = "NO.";
$xlApp->ActiveSheet->Cells(3,1)->Font->Bold = True;
$xlApp->ActiveSheet->Cells(3,1)->VerticalAlignment = -4108;
$xlApp->ActiveSheet->Cells(3,1)->HorizontalAlignment = -4108;
$xlApp->ActiveSheet->Cells(3,1)->BORDERS->Weight = 1;
 
$xlApp->ActiveSheet->Cells(3,2)->Value = "REGISID";
$xlApp->ActiveSheet->Cells(3,2)->Font->Bold = True;
$xlApp->ActiveSheet->Cells(3,2)->VerticalAlignment = -4108;
$xlApp->ActiveSheet->Cells(3,2)->HorizontalAlignment = -4108;
$xlApp->ActiveSheet->Cells(3,2)->BORDERS->Weight = 1;
 
$xlApp->ActiveSheet->Cells(3,3)->Value = "NAME";
$xlApp->ActiveSheet->Cells(3,3)->Font->Bold = True;
$xlApp->ActiveSheet->Cells(3,3)->VerticalAlignment = -4108;
$xlApp->ActiveSheet->Cells(3,3)->HorizontalAlignment = -4108;
$xlApp->ActiveSheet->Cells(3,3)->BORDERS->Weight = 1;
 
$xlApp->ActiveSheet->Cells(3,4)->Value = "DATEREGIS";
$xlApp->ActiveSheet->Cells(3,4)->Font->Bold = True;
$xlApp->ActiveSheet->Cells(3,4)->VerticalAlignment = -4108;
$xlApp->ActiveSheet->Cells(3,4)->HorizontalAlignment = -4108;
$xlApp->ActiveSheet->Cells(3,4)->BORDERS->Weight = 1;
 
$xlApp->ActiveSheet->Cells(3,5)->Value = "LEVELREGIS";
$xlApp->ActiveSheet->Cells(3,5)->Font->Bold = True;
$xlApp->ActiveSheet->Cells(3,5)->VerticalAlignment = -4108;
$xlApp->ActiveSheet->Cells(3,5)->HorizontalAlignment = -4108;
$xlApp->ActiveSheet->Cells(3,5)->BORDERS->Weight = 1;
 
$xlApp->ActiveSheet->Cells(3,6)->Value = "ADDRESS";
$xlApp->ActiveSheet->Cells(3,6)->Font->Bold = True;
$xlApp->ActiveSheet->Cells(3,6)->VerticalAlignment = -4108;
$xlApp->ActiveSheet->Cells(3,6)->HorizontalAlignment = -4108;
$xlApp->ActiveSheet->Cells(3,6)->BORDERS->Weight = 1;

$xlApp->ActiveSheet->Cells(3,7)->Value = "SCHOOL";
$xlApp->ActiveSheet->Cells(3,7)->Font->Bold = True;
$xlApp->ActiveSheet->Cells(3,7)->VerticalAlignment = -4108;
$xlApp->ActiveSheet->Cells(3,7)->HorizontalAlignment = -4108;
$xlApp->ActiveSheet->Cells(3,7)->BORDERS->Weight = 1;

$xlApp->ActiveSheet->Cells(3,8)->Value = "PROVINCE";
$xlApp->ActiveSheet->Cells(3,8)->Font->Bold = True;
$xlApp->ActiveSheet->Cells(3,8)->VerticalAlignment = -4108;
$xlApp->ActiveSheet->Cells(3,8)->HorizontalAlignment = -4108;
$xlApp->ActiveSheet->Cells(3,8)->BORDERS->Weight = 1;
//***********//
 
$intRows = 4;
$num_row = mysql_num_rows($result);
while($objResult = mysql_fetch_array($result))
{
    $count++;
//*** Detail ***//
$xlApp->ActiveSheet->Cells($intRows,1)->Value = $count;
$xlApp->ActiveSheet->Cells($intRows,1)->BORDERS->Weight = 1;
$xlApp->ActiveSheet->Cells($intRows,1)->HorizontalAlignment = -4108;
 
$xlApp->ActiveSheet->Cells($intRows,2)->Value = $objResult[0];
$xlApp->ActiveSheet->Cells($intRows,2)->BORDERS->Weight = 1;
 
$xlApp->ActiveSheet->Cells($intRows,3)->Value = $objResult[1].$objResult[2]." ".$objResult[3];
$xlApp->ActiveSheet->Cells($intRows,3)->BORDERS->Weight = 1;
 
$xlApp->ActiveSheet->Cells($intRows,4)->Value = $objResult[4];
$xlApp->ActiveSheet->Cells($intRows,4)->HorizontalAlignment = -4108;
$xlApp->ActiveSheet->Cells($intRows,4)->BORDERS->Weight = 1;
 
$xlApp->ActiveSheet->Cells($intRows,5)->Value = $objResult[5]." ".$objResult[6];
$xlApp->ActiveSheet->Cells($intRows,5)->BORDERS->Weight = 1;
//$xlApp->ActiveSheet->Cells($intRows,5)->NumberFormat = "$#,##0.00";
 
$xlApp->ActiveSheet->Cells($intRows,6)->Value = $objResult[7]." m.".$objResult[8]." sd.".$objResult[10]." d.".$objResult[11]." p.".$objResult[12];
$xlApp->ActiveSheet->Cells($intRows,6)->BORDERS->Weight = 1;

$xlApp->ActiveSheet->Cells($intRows,7)->Value = $objResult[13];
$xlApp->ActiveSheet->Cells($intRows,7)->BORDERS->Weight = 1;

$xlApp->ActiveSheet->Cells($intRows,8)->Value = $objResult[12];
$xlApp->ActiveSheet->Cells($intRows,8)->BORDERS->Weight = 1;
$intRows++;
}             
 
@unlink($strFileName); //*** Delete old files ***//
 
$xlBook->SaveAs($strPath."/".$strFileName); //*** Save to Path ***//
//$xlBook->SaveAs(realpath($strFileName)); //*** Save to Path ***//
 
//*** Close & Quit ***//
$xlApp->Application->Quit();
$xlApp = null;
$xlBook = null;
$xlSheet1 = null;

//////////////////////////////////////////////////////////    
}
  
//  echo "count: ".$count;
  ?>
<!--  <font color="red">Excel Created <a href="<?=$strFileName?>">Click here</a> to Download.</font>-->
<button name="btExcell" onclick="javascript:window.open('/regisonline/<?=$strFileName?>');">Create File Excel.</button>  
    <tr>
        <td colspan="8" align="right" class="style16bold">จำนวนรวม <?=$count?> ราย</td>
    </tr>
</table>  
<?    
    }
    ?>
</body>
</html>